package com.example.myapplication;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.myapplication.R;

public class NewsDetailFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_news_detail, container, false);

        TextView titleTextView = root.findViewById(R.id.detail_news_title);
        TextView dateTextView = root.findViewById(R.id.detail_news_date);
        WebView webView = root.findViewById(R.id.detail_news_webview);

        Bundle bundle = getArguments();
        if (bundle != null) {
            String title = bundle.getString("news_title");
            String date = bundle.getString("news_date");
            String url = bundle.getString("news_url");

            titleTextView.setText(title);
            dateTextView.setText(date);

            webView.setWebViewClient(new WebViewClient());
            webView.loadUrl(url);
        }

        return root;
    }
}